Spiral Example

FILE: Spiral.cln

Introduction

This is a simple example of the Slider Input, Computer and Polar Graph objects. It draws a spiral onto the polar chart, the spirals spin is determined by the slider.

Switch CleanSheet into automatic recalculation to use this sheet.  When the slider is moved to the top of its travel, the spiral is

Click on any part you need help with.


This is a Slider Input object, it inputs data dynamically into the sheet. In this case it is set up to return values from -30 to +30. This is used by the computer object to step as it winds around the spiral, negative numbers spiral inwards, positive number spiral outwards.


This is a Polar Graph Output object. It takes the array of angles and radii we produced in the Computer object and plots it onto a Polar Chart.


This pipe carries the value from the slider to the computer object.


This pipe carries an array of data points into the Polar Graph object to be plotted.


Computer Object

This is the Computer Object that turns the value input from the slider into a set of coordinates for the spiral.

The program running inside the computer is this:

main{

radius:=1000;

b:={};

i:=0@;

for (ang:=0; ang<1080; ang+=30;) {

b[i]:={ang,radius};

i+=1@;

radius+=a;

};

return transpose(b);

};

It produces an array of coordinates {angle, radius} for the polar graph to plot.


The computer object executes a function called main. The code for the function is enclosed in curly brackets.


The line initializes the radius. The spiral starts at 1000 and either works it way in or out from this point.


We are constructing a result in B, this line clears B (it may be corrupted if we had an input pipe B, but this is normally unnecessary).


The variable i is used to count the points added. Here is it zeroed with the integer 0@;


This For loop steps through the angles 30 degrees a time.


This line assigns a coordinate pair to B.


Increment the number of points.


Adjust the radius.


This closes the For loop


At the moment we have a set of coordinates in B which look like {{0,1000},{30,1200}....}.

What we need is a set of two columns with angles in the first column and radii in the second. This is the Tranposed version of the array.

This is returned as the result of the Computer Object.